﻿@{      
    Layout = "../Shared/_Default.cshtml";
    ViewBag.PageTitle = T(Res.Name("Title"));
    var nonEmptyCarts = (Model.Carts.Items as IEnumerable<dynamic>)
        .Where(x => (x.Items as IEnumerable<dynamic>).Any());
}

<div class="box">
    <section>
        <ul class="unit-list shopping-cart">
        @if(nonEmptyCarts.Any())
        {
            var optAvailable = Model.Options.Items as IEnumerable<dynamic>;
            foreach(var i in nonEmptyCarts)
            {
                var seller = (i.Items as IEnumerable<dynamic>)
                    .Select(x => x.SalesItem.Seller)
                    .First();
                var optSelected = i.Options as IEnumerable<dynamic>;
                <li class="unit shopping-cart">
                    <header>
                        <h3>@JDM.String(seller.DisplayName)</h3>
                    </header>
                    <section>
                    @{
                        Html.RenderPartial("_Items", new 
                        {
                            i.Items,
                            IsOverview = false
                        });
                    }
                    </section>
                    @if(optAvailable.Any())
                    {
                        <section>
                        @{
                            Html.RenderPartial("_Options", new
                            {
                                CartID = JDM.Int32(i.EntityID),
                                Selected = optSelected,
                                Available = optAvailable
                            });
                        }
                        </section>
                    }
                    <footer>
                        <nav>
                            <a class="confirm" href="@Url.Action(Loc.Act("Clear").Set(new
                            {
                                id = JDM.Int32(i.EntityID)             
                            }).Localized())">@T(Res.In("Common").Of("Act").Name("Clear"))</a>
                            <span class="separator">&nbsp;</span>
                            <a href="@Url.Action(Loc.Act("Checkout").Set(new
                            {
                                id = JDM.Int32(i.EntityID)
                            }).Localized())">@T(Res.In("Common").Of("Act").Name("Checkout"))</a>
                        </nav>
                    </footer>
                </li>
            }
        }
        else
        {
            <li class="empty">
                <span>@T(Res.In("Common").Of("Expr").Name("NoData"))</span>
            </li>
        }
        </ul>
    </section>
</div>